package com.hospital.phyexam.impl;

import com.alibaba.fastjson.JSON;
import com.hospital.phyexam.dao.PhyexamInfoMapper;
import com.hospital.phyexam.entity.PhyexamInfo;
import com.hospital.phyexam.service.PhyexamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PhyexamServiceImpl implements PhyexamService {

    @Autowired
    PhyexamInfoMapper phyexamInfoMapper;

    @Override
    public String getByNum(String num) {
        List<PhyexamInfo> phyexamInfos = phyexamInfoMapper.findPhyexamInfoByNum(num);

        List<Map<String, String>> resultMap = new ArrayList<>();
        Map<String, String> map;

        for (PhyexamInfo info : phyexamInfos) {
            map = new HashMap<>();
            map.put("stuNum",info.getStuNum());
            map.put("stuName",info.getStuName());
            resultMap.add(map);
        }
        return JSON.toJSONString(resultMap);

    }

    @Override
    public List<PhyexamInfo> getAll() {
        List<PhyexamInfo> phyexamInfos = phyexamInfoMapper.findAllPhyexamInfo();
        return phyexamInfos;
    }

    @Override
    public void insert() {
        PhyexamInfo phyexamInfo = new PhyexamInfo();
        phyexamInfo.setStuNum(" ");
        phyexamInfoMapper.insertSelective(phyexamInfo);
    }
}
